package com.sky.validator;

import com.jfinal.core.Controller;
import com.jfinal.render.Render;
import com.jfinal.validate.Validator;

/**
 * @author : wushikai
 * <p>
 * date : 2020-07-23
 */
public class LoginValidator extends Validator {

    @Override
    protected void validate(Controller c) {
        this.setShortCircuit(true); //设置短路验证,即一旦有个错误, 直接返回, 底下的就不校验了;
        //如果说你想要 设置 errorKey, 那么你就传json
        validateRequiredString("username","field","username不能为空");
        validateRequiredString("password","field","password不能为空");
        c.renderText("你传上来的 参数有问题 ");
    }

    @Override
    protected void handleError(Controller c) {
        String string = c.getAttr("field").toString();
        c.renderText(string);
    }
}
